package workflowminer.load;

import java.util.Vector;

import workflowminer.domain.Role;
import workflowminer.domain.VarData;
import workflowminer.views.Ventana;

public class ModelViewComunicator {

	private static ModelViewComunicator mwc = null;
	private static Ventana view;
	private static WorkflowLoader loader=null;
	
	private ModelViewComunicator (){
	}
	
	public static ModelViewComunicator getMwc(){
		if (mwc==null) mwc = new ModelViewComunicator();
		return mwc;
	}
	
	public void init(Ventana theView,WorkflowLoader theLoader){
		ModelViewComunicator.loader=theLoader;
		ModelViewComunicator.view=theView;
		ModelViewComunicator.view.init();
	}
	
	public void showVariable(String variable){
		ModelViewComunicator.view.clearMainTable();
		for (VarData data : ModelViewComunicator.loader.getVariable(variable)) {
			ModelViewComunicator.view.addArticuloToTable(data.getVarName(), data.getValue(), data.getOcurrencies());
		};
		ModelViewComunicator.loader.getChartGenerator().generateBarChart(ModelViewComunicator.loader.getVariable(variable));
		view.loadChart();
	}
	
	public void generateGrafic(){
		ModelViewComunicator.loader.getChartGenerator().generateBarChart(loader.getOriginators());
		view.loadChart();
	}

	public static String[] getAllVariables() {
		return loader.getAllVariables();
	}

	public void load(String path) {
		loader.loadWorkFlow(path);
	}

	public Vector<Role> getRoles() {
		return loader.getRoles();
	}
	
}
